<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *设备绑定
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'历史对话'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['id'])){
		$params['agentid']=intval($_RQ['id']);
		$return['params']['id']=$_RQ['id'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_aiagent_useragentlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['title']=base64_decode($item['title']);
			$item['agenttitle']=pdo_getcolumn('jy_aiagent_useragent',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['agentid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$tips='这里删除对话，API接口那边也会同步删除对话的';
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>$tips,'edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'客户信息','type'=>'member'),
			array('name'=>'title','title'=>'对话名称','type'=>'string'),
			array('name'=>'msg_count','title'=>'对话数','type'=>'string'),
			array('name'=>'token_count','title'=>'消耗token','type'=>'string'),
			array('name'=>'mac_address','title'=>'MAC','type'=>'string'),
			array('name'=>'device_id','title'=>'硬件ID','type'=>'string'),
			array('name'=>'model','title'=>'模型','type'=>'string'),
			array('name'=>'agenttitle','title'=>'智能体','type'=>'string'),
			array('name'=>'agentidapi','title'=>'接口智能体ID','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'batch'=>array(
			array('type'=>'model','url'=>'/useragentlogitem/','title'=>'对话详情'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'对话标题','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			$agentlog=pdo_get('jy_aiagent_useragentlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			$this->model('api')->deluseragentlog($agentlog,1);
			pdo_delete('jy_aiagent_useragentlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}